package com.itheima.blog.article.controller;


import com.itheima.api.client.AdminClient;
import com.itheima.api.client.AdminClient;
import com.itheima.api.client.dto.TBannerDto;
import com.itheima.blog.article.dto.TBlogDto;
import com.itheima.api.client.blogAdminReport.ReportVO;
import com.itheima.blog.article.domain.po.vo.CategoryVO;
import com.itheima.blog.article.entity.TBlog;
import com.itheima.blog.article.query.categoryQuery;
import com.itheima.blog.article.query.FilePageQuery;
import com.itheima.blog.article.query.CommentQuery;
import com.itheima.blog.article.query.PageQueryDTO;
import com.itheima.blog.article.service.ITBlogService;
import com.itheima.common.domain.R;
import com.itheima.common.query.PageDTO;
import com.itheima.blog.article.vo.ReplyVO;
import com.itheima.common.domain.PageResDto;
import com.itheima.common.domain.R;
import com.itheima.common.domain.PageReqDto;
import com.itheima.common.domain.PageResDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 博客文章表 前端控制器
 * </p>
 *
 * @author lin
 * @since 2023-07-12
 */
@RestController
@RequestMapping("/blog")
@Api(tags = "文章相关接口")
@RequiredArgsConstructor
public class TBlogController {
    private final ITBlogService blogService;
    private final AdminClient adminFeign;


    @ApiOperation("文章详情展示")
    @GetMapping("/detail")
    public List<TBlog> blogDetail(@RequestParam Long blogId){
        return blogService.blogDetail(blogId);
    }
    @ApiOperation("相关文章")
    @GetMapping("/rel/{categoryId}")
    public List<TBlog> relatedBlog(@PathVariable("categoryId") Long categoryId){
        return blogService.relatedBlog(categoryId);
    }

    @ApiOperation("轮播图列表展示")
    @GetMapping("/list")
    public PageResDto<TBannerDto> findBannerList(PageReqDto pageReqDto){
        return adminFeign.findPage(pageReqDto);
    }

    @ApiOperation("文章列表分页展示")
    @GetMapping("/page")
    public PageResDto<TBlog> findBlogByPage(TBlogDto tBlogDto){
        return blogService.findBlogByPage(tBlogDto);
    }


    @GetMapping("/fingLogAndCommentNumber")
    @ApiOperation("首页文章和评论总数展示")
    public ReportVO fingLogAndCommentNumber() {
        return blogService.fingLogAndCommentNumber();
    }

    @GetMapping("/classificationNumber")
    @ApiOperation("每个分类的文章数")
    public List<Long> classificationNumber(@RequestParam("categoryIds") List<Integer> categoryIds) {
        return blogService.classificationNumber(categoryIds);
    }

    @GetMapping("/labelNumber")
    @ApiOperation("每个标签的文章数")
    public ReportVO labelNumber() {
        return blogService.labelNumber();
    }

    @GetMapping("/provinceBlogs")
    @ApiOperation("每个省份发博客数量(地图)")
    public List<ReportVO> provinceBlogs(@RequestParam("type") Integer type) {
        return blogService.provinceBlogs(type);
    }

    @GetMapping("/contributeForLastYear")
    @ApiOperation("文章贡献度")
    public ReportVO contributeForLastYear() {
        return blogService.contributeForLastYear();
    }


    @GetMapping("/category/list")
    @ApiOperation("分类列表")
    public R classificationList() {
        return R.ok(adminFeign.classificationList());
    }

    @GetMapping("/category/{categoryId}")
    @ApiOperation("按照分类查询文章列表（带分页、按时间倒叙）")
    public R<PageDTO<CategoryVO>> categoryPage(categoryQuery query) {
        return R.ok(blogService.categoryPage(query));
    }

    @GetMapping("/month/{yyyy-mm}")
    @ApiOperation("归档")
    public R filePage(@RequestBody FilePageQuery filePageQuery, @PathVariable("yyyy-mm") String data) {
        filePageQuery.setDate(data);
        PageDTO<CategoryVO> categoryVOPageDTO = blogService.filePage(filePageQuery);
        return R.ok(categoryVOPageDTO);
    }
}
